package com.gsc.funnycode.ctrl;

import com.alibaba.druid.support.json.JSONUtils;
import com.gsc.funnycode.entity.User;
import com.gsc.funnycode.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Orange
 * @Date: 15:50 2022/4/27
 */
@Api(tags = "HelloWord!!")
@Slf4j
@RestController
public class HelloWordController {

    @Autowired
    UserService userService;
    @Autowired
    RedisTemplate redisTemplate;

    @ApiOperation("HelloWorld")
    @PostMapping("/helloWorld/{info}")
    public String helloWord(@PathVariable("info") String info){
        return "Hello World" + info;
    }

//    @GetMapping("/TestDB")
    public List<User> dbTest(){
        return userService.list();
    }

//    @GetMapping("/redisTest")
    public String redisTest(){
        Object gsc = redisTemplate.opsForValue().get("GSC");
        log.info("redis查询内容：{}",gsc);
        return JSONUtils.toJSONString(gsc);
    }
}
